{% extends "base_portadmin.html" %}

{% block object-tools %}
	<ul class="object-tools">
		<li>
			<a class="addlink" href="/portadmin/system/add/">Add JRC system</a>
	    </li>
    </ul>

{% endblock %}

{% block mainheading %}{{ block.super }} \ Systems{% endblock %}

{% block content %}

		<div id="ParametersLoader" style="display: none;"><img src="http://sunnystars.eu/images/ajaxloading.gif" alt="Loading..." /></div>

		<div>
			<table cellspacing="0">
		
				<thead>
				<tr>
				<th class="action-checkbox-column"></th><th>
				PK
				</th><th>
				Name
				</th><th>
				<select id="StatusId" name="status_id" onchange="JrcLoadSystems();">
					<option value="0">Status id</option>
					{# for item in MyConstants.STATUS_CHOICES #}
						<option value="1">approved</option>
						<option value="2">deleted</option>
					{# endfor #}
				</select>
				</th><th>
				Created at
				</th><th>
				Actions
				</th>
				</tr>
				</thead>
		
				<tbody id="ParametersTbody">
				</tbody>
			</table>			
		</div>

<script type="text/javascript">

	var gIsOperationLoaded = true;

	function JrcLoadSystems()
	{
		if( gIsOperationLoaded )
		{
			gIsOperationLoaded = false;
			jQuery("#ParametersLoader").show();
			
			jQuery.ajax({
				url: "/portadmin/1/getsystems/"
				, data: "status_id=" + jQuery("#StatusId").val()
				//, data: "system_id=" + systemId + "&market_id=" + marketId
				, success: function(data){ OnJrcSystemsLoaded(data); }
				, error: function(){ OnJrcSystemsFailed(); }
				, cache: false
			});
		}
	}

	function OnJrcSystemsLoaded(data)
	{
		gIsOperationLoaded = true;
		jQuery("#ParametersLoader").hide();
		jQuery("#ParametersTbody").html(data);
	}

	function OnJrcSystemsFailed()
	{
		gIsOperationLoaded = true;
		jQuery("#ParametersLoader").hide();
		jQuery("#ParametersTbody").html("<tr><td colspan='5'>Error loading data!</td></tr>");
	}

</script>

{% endblock %}


{% block js_on_load %}

	{{ block.super }}
	
	// Loading initial parameters
	JrcLoadSystems();

{% endblock %}
